<?php
require_once '../model/model.php';
use admin\Model\model as m;

$m = new m();
if(!empty($_GET['_search'] && $_GET['_search'] == 'false')){
	$page = 1;
	$row = 1;
	$sidx = 'id';
	$sort = 'asc';
	if(!is_null($_GET['page'])){
		$page = $_GET['page'];
	}
	if(!is_null($_GET['rows'])){
		$row = $_GET['rows'];
	}
	if(!empty($_GET['sidx'])){
		$sidx = $_GET['sidx'];
	}
	if(!empty($_GET['sord'])) {
		$sort = $_GET['sord'];
	}
	$a = $m->json_table_user($row,$page,$sidx,$sort);
	$array = array();
	$array['records'] = $a['num'];
	$array['total'] = ceil($a['num']/$row);
	$array['page'] = $page;
	$array['rows'] = $a['rows'];
	exit(json_encode($array));
}else if (!empty($_GET['_search']) && $_GET['_search'] == 'true' && $_GET['searchOper'] == 'eq') {
	$page = 1;
	$row = 1;
	$sidx = 'id';
	$sort = 'asc';
	if(!is_null($_GET['page'])){
		$page = $_GET['page'];
	}
	if(!is_null($_GET['rows'])){
		$row = $_GET['rows'];
	}
	if(!empty($_GET['sidx'])){
		$sidx = $_GET['sidx'];
	}
	if(!empty($_GET['sord'])) {
		$sort = $_GET['sord'];
	}
	if(!empty($_GET['searchString'])) {
		$str = $_GET['searchString'];
	}
	if(!empty($_GET['searchField'])) {
		$search = $_GET['searchField'];
	}
	$a = $m->search_user($str,$search);
	$array = array();
	$array['records'] = $a['num'];
	$array['total'] = ceil($a['num']/$row);
	$array['page'] = $page;
	$array['rows'] = $a['rows'];
	exit(json_encode($array));
}